package com.papa91.arcapp;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Display;
import android.view.InputDevice;

import com.papa91.common.BaseAppConfig;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.util.regex.Pattern;

public class AppConfig extends BaseAppConfig
{

//	static public String PATH = "/papa91os/arc/";
	static public String PATH = "papa91os/arc/";
	//static public String APP_PATH = "";
	static
	{
		EMU_NAME = "arc";
//		File dateDir = Environment.getExternalStorageDirectory();
//		PRIVATE_PATH = dateDir.getAbsolutePath() + PATH;// context.getExternalFilesDir(null).toString()+"/";
//		APP_PATH = dateDir.getAbsolutePath() + PATH;// PRIVATE_PATH;//

//        PRIVATE_PATH = MyApplication.getMyApplication().getAppRootPath() + PATH;
//		APP_PATH = MyApplication.getMyApplication().getAppRootPath() + PATH;

		Log.e("AppConfig_tbl", "AppConfig_tbl>>>PRIVATE_PATH:"+PRIVATE_PATH);
		Log.e("AppConfig_tbl", "AppConfig_tbl>>>APP_PATH:"+APP_PATH);

		ROM_PATH = APP_PATH;
		// STATE_PATH = PRIVATE_PATH + ".states/";
		CONFIG_PATH = PRIVATE_PATH + CONFIG_PATH;
		INFO_PATH = PRIVATE_PATH + INFO_PATH;
		// SNAP_PATH = PRIVATE_PATH + ".snapshot/";
		// CHEAT_PATH = PRIVATE_PATH + ".cheats/";
		IPS_PATH = PRIVATE_PATH + IPS_PATH;
		TMP_PATH = PRIVATE_PATH + TMP_PATH;
		ROMDATA_PATH = PRIVATE_PATH + ROMDATA_PATH;
		LOG_PATH = PRIVATE_PATH + LOG_PATH;

	}
	
	static public String strPgmGame []= {
			//----d_pgm.cpp  
	//----d_cps1.cpp  
			"BurnDrvCps1941",  
			"BurnDrvCps1941r1",  
			"BurnDrvCps1941u",  
			"BurnDrvCps1941j",  
			"BurnDrvCps3wonders",  
			"BurnDrvCps3wondersr1",  
			"BurnDrvCps3wondersu",  
			"BurnDrvCpsWonder3",  
			"BurnDrvCps3wondersh",  
			"BurnDrvCps3wondersb",  
			"BurnDrvCpsCaptcomm",  
			"BurnDrvCpsCaptcommr1",  
			"BurnDrvCpsCaptcommu",  
			"BurnDrvCpsCaptcommj",  
			"BurnDrvCpsCaptcommjr1",  
			"BurnDrvCpsCaptcommb",  
			"BurnDrvCpsCaptcommb2",  
			"BurnDrvCpsCawing",  
			"BurnDrvCpsCawingr1",  
			"BurnDrvCpsCawingu",  
			"BurnDrvCpsCawingj",  
			"BurnDrvCpsCawingbl",  
			"BurnDrvCpsCawingb2",  
			"BurnDrvCpsCps1demo",  
			"BurnDrvCpsCworld2j",  
			"BurnDrvCpsDino",  
			"BurnDrvCpsDinoz",  
			"BurnDrvCpsDinoxa",  
			"BurnDrvCpsDinoxb",  
			"BurnDrvCpsDinoxc",  
			"BurnDrvCpsDinoxd",  
			"BurnDrvCpsDinoxe",  
			"BurnDrvCpsDinoj",  
			"BurnDrvCpsDinou",  
			"BurnDrvCpsDinopic",  
			"BurnDrvCpsDinopic2",  
			"BurnDrvCpsDinopic3",  
			"BurnDrvCpsDinoh",  
			"BurnDrvCpsDinot",  
			"BurnDrvCpsDinotpic",  
			"BurnDrvCpsDinohunt",  
			"BurnDrvCpsDinoeh",  
			"BurnDrvCpsDinohc",  
			"BurnDrvCpsDynwar",  
			"BurnDrvCpsDynwara",  
			"BurnDrvCpsDynwarj",  
			"BurnDrvCpsDynwarjr",  
			"BurnDrvCpsFfight",  
			"BurnDrvCpsFfighta",  
			"BurnDrvCpsFfightu",  
			"BurnDrvCpsFfightu1",  
			"BurnDrvCpsFfightua",  
			"BurnDrvCpsFfightub",  
			"BurnDrvCpsFfightj",  
			"BurnDrvCpsFfightj1",  
			"BurnDrvCpsFfightj2",  
			"BurnDrvCpsFfightj3",  
			"BurnDrvCpsFfightjh",  
			"BurnDrvCpsFfightbl",  
			"BurnDrvCpsFfightbl2",  
			"BurnDrvCpsFcrash",  
			"BurnDrvCpsForgottn",  
			"BurnDrvCpsForgottnu",  
			"BurnDrvCpsForgottnu1",  
			"BurnDrvCpsForgottnua",  
			"BurnDrvCpsForgottnuaa",  
			"BurnDrvCpsLostwrld",  
			"BurnDrvCpsLostwrldo",  
			"BurnDrvCpsGanbare",  
			"BurnDrvCpsGhouls",  
			"BurnDrvCpsGhoulsu",  
			"BurnDrvCpsDaimakai",  
			"BurnDrvCpsDaimakair",  
			"BurnDrvCpsDaimakaib",  
			"BurnDrvCpsKnights",  
			"BurnDrvCpsKnightsboos",  
			"BurnDrvCpsKnightsu",  
			"BurnDrvCpsKnightsj",  
			"BurnDrvCpsKnightsja",  
			"BurnDrvCpsKnightsb",  
			"BurnDrvCpsKnightsb2",  
			"BurnDrvCpsKnightsb3",  
			"BurnDrvCpsKnightsb4",  
			"BurnDrvCpsKnightsh",  
			"BurnDrvCpsKnightsh2",  
			"BurnDrvCpsKod",  
			"BurnDrvCpsKodr1",  
			"BurnDrvCpsKodu",  
			"BurnDrvCpsKodj",  
			"BurnDrvCpsKodja",  
			"BurnDrvCpsKodb",  
			"BurnDrvCpsKodh",  
			"BurnDrvCpsKodda",  
			"BurnDrvCpsMegaman",  
			"BurnDrvCpsMegamana",  
			"BurnDrvCpsRockmanj",  
			"BurnDrvCpsMercs",  
			"BurnDrvCpsMercsu",  
			"BurnDrvCpsMercsur1",  
			"BurnDrvCpsMercsj",  
			"BurnDrvCpsMsword",  
			"BurnDrvCpsMswordr1",  
			"BurnDrvCpsMswordj",  
			"BurnDrvCpsMswordu",  
			"BurnDrvCpsMtwins",  
			"BurnDrvCpsChikij",  
			"BurnDrvCpsNemo",  
			"BurnDrvCpsNemor1",  
			"BurnDrvCpsNemoj",  
			"BurnDrvCpsPang3",  
			"BurnDrvCpsPang3r1",  
			"BurnDrvCpsPang3r1a",  
			"BurnDrvCpsPang3b",  
			"BurnDrvCpsPang3b2",  
			"BurnDrvCpsPang3b3",  
			"BurnDrvCpsPang3j",  
			"BurnDrvCpsPnickj",  
			"BurnDrvCpsPunisher",  
			"BurnDrvCpsPunisheru",  
			"BurnDrvCpsPunisherj",  
			"BurnDrvCpsPunisherh",  
			"BurnDrvCpsPunipic",  
			"BurnDrvCpsPunipic2",  
			"BurnDrvCpsPunipic3",  
			"BurnDrvCpsPunisherbz",  
			"BurnDrvCpsQad",  
			"BurnDrvCpsQadjr",  
			"BurnDrvCpsQtono2j",  
			"BurnDrvCpsSf2",  
			"BurnDrvCpsSf2eb",  
			"BurnDrvCpsSf2ed",  
			"BurnDrvCpsSf2ee",  
			"BurnDrvCpsSf2ebbl",  
			"BurnDrvCpsSf2ebbl2",  
			"BurnDrvCpsSf2stt",  
			"BurnDrvCpsSf2ua",  
			"BurnDrvCpsSf2ub",  
			"BurnDrvCpsSf2uc",  
			"BurnDrvCpsSf2ud",  
			"BurnDrvCpsSf2ue",  
			"BurnDrvCpsSf2uf",  
			"BurnDrvCpsSf2ug",  
			"BurnDrvCpsSf2ui",  
			"BurnDrvCpsSf2uk",  
			"BurnDrvCpsSf2j",  
			"BurnDrvCpsSf2ja",  
			"BurnDrvCpsSf2jc",  
			"BurnDrvCpsSf2jf",  
			"BurnDrvCpsSf2jh",  
			"BurnDrvCpsSf2jl",  
			"BurnDrvCpsSf2qp1",  
			"BurnDrvCpsSf2thndr",  
			"BurnDrvCpsSf2b",  
			"BurnDrvCpsSf2b2",  
			"BurnDrvCpsSf2ce",  
			"BurnDrvCpsSf2ceea",  
			"BurnDrvCpsSf2ceja",  
			"BurnDrvCpsSf2cejb",  
			"BurnDrvCpsSf2cejc",  
			"BurnDrvCpsSf2ceua",  
			"BurnDrvCpsSf2ceub",  
			"BurnDrvCpsSf2ceuc",  
			"BurnDrvCpsSf2acc",  
			"BurnDrvCpsSf2acca",  
			"BurnDrvCpsSf2accp2",  
			"BurnDrvCpsSf2dkot2",  
			"BurnDrvCpsSf2rb",  
			"BurnDrvCpsSf2rb2",  
			"BurnDrvCpsSf2rb3",  
			"BurnDrvCpsSf2rb4",  
			"BurnDrvCpsSf2rb5",  
			"BurnDrvCpsSf2rb6",  
			"BurnDrvCpsSf2red",  
			"BurnDrvCpsSf2red2",  
			"BurnDrvCpsSf2v004",  
			"BurnDrvCpsSf2v0042",  
			"BurnDrvCpsSf2v0043",  
			"BurnDrvCpsSf2dongb",  
			"BurnDrvCpsSf2bhh",  
			"BurnDrvCpsSf2hf",  
			"BurnDrvCpsSf2hfu",  
			"BurnDrvCpsSf2hfj",  
			"BurnDrvCpsSf2hfjb",  
			"BurnDrvCpsSf2hfjb2",  
			"BurnDrvCpsSf2yyc",  
			"BurnDrvCpsSf2yyc2",  
			"BurnDrvCpsSf2koryu",  
			"BurnDrvCpsSf2koryu2",  
			"BurnDrvCpsSf2koryu3",  
			"BurnDrvCpsSf2amf",  
			"BurnDrvCpsSf2amf2",  
			"BurnDrvCpsSf2amf3",  
			"BurnDrvCpsSf2amf4",  
			"BurnDrvCpsSf2amf5",  
			"BurnDrvCpsSf2amf6",  
			"BurnDrvCpsSf2amf7",  
			"BurnDrvCpsSf2amf8",  
			"BurnDrvCpsSf2mega",  
			"BurnDrvCpsSf2mega2",  
			"BurnDrvCpsSf2md",  
			"BurnDrvCpsSf2mdt",  
			"BurnDrvCpsSf2mdta",  
			"BurnDrvCpsSf2mdtb",  
			"BurnDrvCpsSf2ceeabl",  
			"BurnDrvCpsSf2ceeab2",  
			"BurnDrvCpsSf2cejabl",  
			"BurnDrvCpsSf2cejab2",  
			"BurnDrvCpsSf2ceuabl",  
			"BurnDrvCpsSf2ceuab2",  
			"BurnDrvCpsSf2ceuab3",  
			"BurnDrvCpsSf2ceuab4",  
			"BurnDrvCpsSf2ceuab5",  
			"BurnDrvCpsSf2ceuab6",  
			"BurnDrvCpsSf2ceuab7",  
			"BurnDrvCpsSf2ceucbl",  
			"BurnDrvCpsSf2tlona",  
			"BurnDrvCpsSf2tlonb",  
			"BurnDrvCpsSf2tlonc",  
			"BurnDrvCpsSf2sl73a",  
			"BurnDrvCpsSfzch",  
			"BurnDrvCpsSlammast",  
			"BurnDrvCpsSlammastu",  
			"BurnDrvCpsMbomberj",  
			"BurnDrvCpsMbombrd",  
			"BurnDrvCpsMbombrdj",  
			"BurnDrvCpsSlampic",  
			"BurnDrvCpsStrider",  
			"BurnDrvCpsStriderua",  
			"BurnDrvCpsStriderjr",  
			"BurnDrvCpsStriderj",  
			"BurnDrvCpsUnsquad",  
			"BurnDrvCpsArea88",  
			"BurnDrvCpsArea88r",  
			"BurnDrvCpsVarth",  
			"BurnDrvCpsVarthr1",  
			"BurnDrvCpsVarthj",  
			"BurnDrvCpsVarthu",  
			"BurnDrvCpsWillow",  
			"BurnDrvCpsWillowo",  
			"BurnDrvCpsWillowj",  
			"BurnDrvCpsWof",  
			"BurnDrvCpsWofr1",  
			"BurnDrvCpsWofu",  
			"BurnDrvCpsWofj",  
			"BurnDrvCpsWofjz",  
			"BurnDrvCpsWofab",  
			"BurnDrvCpsWofjxa",  
			"BurnDrvCpsWofjxb",  
			"BurnDrvCpsWofjxc",  
			"BurnDrvCpsWofjxd",  
			"BurnDrvCpsWofjxe",  
			"BurnDrvCpsWofa",  
			"BurnDrvCpsWofch",  
			"BurnDrvCpsWofhfh",  
			"BurnDrvCpsWofh",  
			"BurnDrvCpsWofha",  
			"BurnDrvCpsSgyxz",  
			"BurnDrvCpsWof3js",  
			"BurnDrvCpsWof3jsa",  
			"BurnDrvCpsWof3sj",  
			"BurnDrvCpsWof3sja",  
			"BurnDrvCpsWofsj",  
			"BurnDrvCpsWofsja",  
			"BurnDrvCpsWofsjb",  
			"BurnDrvCpsWofb",  
			"BurnDrvCpsWofjh",  
			"BurnDrvCpsWofah",  
			"BurnDrvCpsWofaha",  
			"BurnDrvCpsWofahb",  
			"BurnDrvCpsCps1frog",  
  
//----d_cps2.cpp  
			"BurnDrvCps19xx",  
			"BurnDrvCps19xxa",  
			"BurnDrvCps19xxb",  
			"BurnDrvCps19xxh",  
			"BurnDrvCps19xxj",  
			"BurnDrvCps19xxjr1",  
			"BurnDrvCps19xxjr2",  
			"BurnDrvCps1944",  
			"BurnDrvCps1944j",  
			"BurnDrvCpsArmwar",  
			"BurnDrvCpsArmwarr1",  
			"BurnDrvCpsArmwaru",  
			"BurnDrvCpsArmwaru1",  
			"BurnDrvCpsPgear",  
			"BurnDrvCpsPgearr1",  
			"BurnDrvCpsArmwara",  
			"BurnDrvCpsArmwarar1",  
			"BurnDrvCpsAvsp",  
			"BurnDrvCpsAvspa",  
			"BurnDrvCpsAvsph",  
			"BurnDrvCpsAvspj",  
			"BurnDrvCpsAvspu",  
			"BurnDrvCpsBatcir",  
			"BurnDrvCpsBatcira",  
			"BurnDrvCpsBatcirj",  
			"BurnDrvCpsChoko",  
			"BurnDrvCpsCsclub",  
			"BurnDrvCpsCsclub1",  
			"BurnDrvCpsCscluba",  
			"BurnDrvCpsCsclubh",  
			"BurnDrvCpsCsclubj",  
			"BurnDrvCpsCsclubjr",  
			"BurnDrvCpsCybots",  
			"BurnDrvCpsCybotsj",  
			"BurnDrvCpsCybotsu",  
			"BurnDrvCpsDdsom",
			"BurnDrvCpsDdsomr1",  
			"BurnDrvCpsDdsomr2",  
			"BurnDrvCpsDdsomr3",  
			"BurnDrvCpsDdsoma",  
			"BurnDrvCpsDdsomb",  
			"BurnDrvCpsDdsomh",  
			"BurnDrvCpsDdsomj",  
			"BurnDrvCpsDdsomchs",  
			"BurnDrvCpsDdsomjr1",  
			"BurnDrvCpsDdsomu",  
			"BurnDrvCpsDdsomur1",  
			"BurnDrvCpsDdtod",  
			"BurnDrvCpsDdtodr1",  
			"BurnDrvCpsDdtoda",  
			"BurnDrvCpsDdtodar1",  
			"BurnDrvCpsDdtodh",  
			"BurnDrvCpsDdtodhr1",  
			"BurnDrvCpsDdtodhr2",  
			"BurnDrvCpsDdtodj",  
			"BurnDrvCpsDdtodjr1",  
			"BurnDrvCpsDdtodjr2",  
			"BurnDrvCpsDdtodu",  
			"BurnDrvCpsDdtodur1",  
			"BurnDrvCpsDimahoo",  
			"BurnDrvCpsGreatMahouDaiJ",  
			"BurnDrvCpsDimahoou",  
			"BurnDrvCpsDstlk",  
			"BurnDrvCpsDstlka",  
			"BurnDrvCpsDstlkh",  
			"BurnDrvCpsDstlku",  
			"BurnDrvCpsDstlkur1",  
			"BurnDrvCpsVampj",  
			"BurnDrvCpsVampja",  
			"BurnDrvCpsVampjr1",  
			"BurnDrvCpsEcofghtr",  
			"BurnDrvCpsEcofghtra",  
			"BurnDrvCpsEcofghtrh",  
			"BurnDrvCpsEcofghtru",  
			"BurnDrvCpsEcofghtru1",  
			"BurnDrvCpsUecology",  
			"BurnDrvCpsGigawing",  
			"BurnDrvCpsGigawinga",  
			"BurnDrvCpsGigawingb",  
			"BurnDrvCpsGigawingh",  
			"BurnDrvCpsGigawingj",  
			"BurnDrvCpsHsf2",  
			"BurnDrvCpsHsf2a",  
			"BurnDrvCpsHsf2j",  
			"BurnDrvCpsJyangoku",  
			"BurnDrvCpsMegaman2",  
			"BurnDrvCpsMegaman2a",  
			"BurnDrvCpsMegaman2h",  
			"BurnDrvCpsRockman2j",  
			"BurnDrvCpsMmancp2u",  
			"BurnDrvCpsRmancp2j",  
			"BurnDrvCpsMarsMatrix",  
			"BurnDrvCpsMarsMatrixJ",  
			"BurnDrvCpsMPang",  
			"BurnDrvCpsMPangr1",  
			"BurnDrvCpsMPangu",  
			"BurnDrvCpsMPangj",  
			"BurnDrvCpsMsh",  
			"BurnDrvCpsMsha",  
			"BurnDrvCpsMshb",  
			"BurnDrvCpsMshh",  
			"BurnDrvCpsMshj",  
			"BurnDrvCpsMshjr1",  
			"BurnDrvCpsMshu",  
			"BurnDrvCpsMshvsf",  
			"BurnDrvCpsMshvsfa",  
			"BurnDrvCpsMshvsfa1",  
			"BurnDrvCpsMshvsfb",  
			"BurnDrvCpsMshvsfb1",  
			"BurnDrvCpsMshvsfh",  
			"BurnDrvCpsMshvsfj",  
			"BurnDrvCpsMshvsfj1",  
			"BurnDrvCpsMshvsfj2",  
			"BurnDrvCpsMshvsfu",  
			"BurnDrvCpsMshvsfu1",  
			"BurnDrvCpsMvsc",  
			"BurnDrvCpsMvscr1",  
			"BurnDrvCpsMvsca",  
			"BurnDrvCpsMvscar1",  
			"BurnDrvCpsMvscb",  
			"BurnDrvCpsMvsch",  
			"BurnDrvCpsMvscj",  
			"BurnDrvCpsMvscjr1",  
			"BurnDrvCpsMvscu",  
			"BurnDrvCpsMvscur1",  
			"BurnDrvCpsMvscjsing",  
			"BurnDrvCpsNwarr",  
			"BurnDrvCpsNwarra",  
			"BurnDrvCpsNwarrb",  
			"BurnDrvCpsNwarrh",  
			"BurnDrvCpsNwarru",  
			"BurnDrvCpsVhuntj",  
			"BurnDrvCpsVhuntjr1s",  
			"BurnDrvCpsVhuntjr1",  
			"BurnDrvCpsVhuntjr2",  
			"BurnDrvCpsProgear",  
			"BurnDrvCpsProgeara",  
			"BurnDrvCpsProgearj",  
			"BurnDrvCpsPzloop2",  
			"BurnDrvCpsPzloop2j",  
			"BurnDrvCpsPzloop2jr1",  
			"BurnDrvCpsQndream",  
			"BurnDrvCpsRingdest",  
			"BurnDrvCpsSmbomb",  
			"BurnDrvCpsSmbombr1",  
			"BurnDrvCpsRingdesta",  
			"BurnDrvCpsSfa",  
			"BurnDrvCpsSfar1",  
			"BurnDrvCpsSfar2",  
			"BurnDrvCpsSfar3",  
			"BurnDrvCpsSfau",  
			"BurnDrvCpsSfza",  
			"BurnDrvCpsSfzar1",  
			"BurnDrvCpsSfzb",  
			"BurnDrvCpsSfzbr1",  
			"BurnDrvCpsSfzh",  
			"BurnDrvCpsSfzhr1",  
			"BurnDrvCpsSfzj",  
			"BurnDrvCpsSfzjr1",  
			"BurnDrvCpsSfzjr2",  
			"BurnDrvCpsSfa2",  
			"BurnDrvCpsSfa2u",  
			"BurnDrvCpsSfa2ur1",  
			"BurnDrvCpsSfz2a",  
			"BurnDrvCpsSfz2b",  
			"BurnDrvCpsSfz2br1",  
			"BurnDrvCpsSfz2h",  
			"BurnDrvCpsSfz2j",  
			"BurnDrvCpsSfz2jr1",  
			"BurnDrvCpsSfz2n",  
			"BurnDrvCpsSfz2al",  
			"BurnDrvCpsSfz2alb",  
			"BurnDrvCpsSfz2alh",  
			"BurnDrvCpsSfz2alj",  
			"BurnDrvCpsSfa3",  
			"BurnDrvCpsSfa3b",  
			"BurnDrvCpsSfa3h",  
			"BurnDrvCpsSfa3hr1",  
			"BurnDrvCpsSfa3u",  
			"BurnDrvCpsSfa3ur1",  
			"BurnDrvCpsSfz3a",  
			"BurnDrvCpsSfz3ar1",  
			"BurnDrvCpsSfz3j",  
			"BurnDrvCpsSfz3jr1",  
			"BurnDrvCpsSfz3jr2",  
			"BurnDrvCpsSgemf",  
			"BurnDrvCpsPfghtj",  
			"BurnDrvCpsSgemfa",  
			"BurnDrvCpsSgemfh",  
			"BurnDrvCpsSpf2t",  
			"BurnDrvCpsSpf2xj",  
			"BurnDrvCpsSpf2ta",  
			"BurnDrvCpsSpf2th",  
			"BurnDrvCpsSsf2",  
			"BurnDrvCpsSsf2a",  
			"BurnDrvCpsSsf2ar1",  
			"BurnDrvCpsSsf2h",  
			"BurnDrvCpsSsf2j",  
			"BurnDrvCpsSsf2jr1",  
			"BurnDrvCpsSsf2jr2",  
			"BurnDrvCpsSsf2u",  
			"BurnDrvCpsSsf2tb",  
			"BurnDrvCpsSsf2tbr1",  
			"BurnDrvCpsSsf2tbj",  
			"BurnDrvCpsSsf2tbh",  
			"BurnDrvCpsSsf2t",  
			"BurnDrvCpsSsf2ta",  
			"BurnDrvCpsSsf2tu",  
			"BurnDrvCpsSsf2tur1",  
			"BurnDrvCpsSsf2xj",  
			"BurnDrvCpsSsf2xjr",  
			"BurnDrvCpsVhunt2",  
			"BurnDrvCpsVhunt2r1",  
			"BurnDrvCpsVsav",  
			"BurnDrvCpsVsava",  
			"BurnDrvCpsVsavh",  
			"BurnDrvCpsVsavj",  
			"BurnDrvCpsVsavu",  
			"BurnDrvCpsVsav2",  
			"BurnDrvCpsXmcota",  
			"BurnDrvCpsXmcotar1",  
			"BurnDrvCpsXmcotaa",  
			"BurnDrvCpsXmcotaar1",  
			"BurnDrvCpsXmcotah",  
			"BurnDrvCpsXmcotahr1",  
			"BurnDrvCpsXmcotaj",  
			"BurnDrvCpsXmcotaj1",  
			"BurnDrvCpsXmcotaj2",  
			"BurnDrvCpsXmcotaj3",  
			"BurnDrvCpsXmcotajr",  
			"BurnDrvCpsXmcotau",  
			"BurnDrvCpsXmvsf",  
			"BurnDrvCpsXmvsfr1",  
			"BurnDrvCpsXmvsfa",  
			"BurnDrvCpsXmvsfar1",  
			"BurnDrvCpsXmvsfar2",  
			"BurnDrvCpsXmvsfar3",  
			"BurnDrvCpsXmvsfb",  
			"BurnDrvCpsXmvsfh",  
			"BurnDrvCpsXmvsfj",  
			"BurnDrvCpsXmvsfjr1",  
			"BurnDrvCpsXmvsfjr2",  
			"BurnDrvCpsXmvsfu",  
			"BurnDrvCpsXmvsfur1",  
			"BurnDrvCps19xxd",  
			"BurnDrvCps1944d",  
			"BurnDrvCps1944ad",  
			"BurnDrvCpsArmwar1d",  
			"BurnDrvCpsAvspd",  
			"BurnDrvCpsBatcird",  
			"BurnDrvCpsCsclub1d",  
			"BurnDrvCpsCybotsud",  
			"BurnDrvCpsCybotsjd",  
			"BurnDrvCpsDdsomud",  
			"BurnDrvCpsDdtodd",  
			"BurnDrvCpsDimahoud",  
			"BurnDrvCpsDstlku1d",  
			"BurnDrvCpsEcofghtrd",  
			"BurnDrvCpsGigawingd",  
			"BurnDrvCpsGigawingjd",  
			"BurnDrvCpsHsf2d",  
			"BurnDrvCpsHsf2da",  
			"BurnDrvCpsMegamn2d",  
			"BurnDrvCpsMarsMatrixd",  
			"BurnDrvCpsMPangjd",  
			"BurnDrvCpsMshud",  
			"BurnDrvCpsMshvsfu1d",  
			"BurnDrvCpsMvscud",  
			"BurnDrvCpsNwarrud",  
			"BurnDrvCpsProgearud",  
			"BurnDrvCpsProgearjd",  
			"BurnDrvCpsRingdstd",  
			"BurnDrvCpsSfad",  
			"BurnDrvCpsSfaud",  
			"BurnDrvCpsSfz2ad",  
			"BurnDrvCpsSfz2jd",  
			"BurnDrvCpsSfz2ald",  
			"BurnDrvCpsSfa3ud",  
			"BurnDrvCpsSfz3jr2d",  
			"BurnDrvCpsSgemfd",  
			"BurnDrvCpsSpf2td",  
			"BurnDrvCpsSpf2xjd",  
			"BurnDrvCpsSsf2d",  
			"BurnDrvCpsSsf2ud",  
			"BurnDrvCpsSsf2tbd",  
			"BurnDrvCpsSsf2td",  
			"BurnDrvCpsSsf2tad",  
			"BurnDrvCpsSsf2xjd",  
			"BurnDrvCpsVsavd",  
			"BurnDrvCpsVhunt2d",  
			"BurnDrvCpsVsav2d",  
			"BurnDrvCpsXmcotar1d",  
			"BurnDrvCpsXmvsfu1d",  
			"BurnDrvCpsProgearjbl",  
			"BurnDrvCpsGigaman2",  
  
//----d_neogeo.cpp  
			"BurnDrvNeoGeo",  
			"BurnDrvNeoGeoMVS",  
			"BurnDrvneocdz",  
			"BurnDrvNam1975",  
			"BurnDrvBstars",  
			"BurnDrvBstarsh",  
			"BurnDrvTpgolf",  
			"BurnDrvMahretsu",  
			"BurnDrvRidhero",  
			"BurnDrvRidheroh",  
			"BurnDrvAlpham2",  
			"BurnDrvAlpham2p",  
			"BurnDrvCyberlip",  
			"BurnDrvSuperspy",  
			"BurnDrvMutnat",  
			"BurnDrvKotm",  
			"BurnDrvKotmh",  
			"BurnDrvSengoku",  
			"BurnDrvSengokuh",  
			"BurnDrvBurningf",  
			"BurnDrvBurningfh",  
			"BurnDrvBurningfp",  
			"BurnDrvLbowling",  
			"BurnDrvGpilots",  
			"BurnDrvGpilotsh",  
			"BurnDrvJoyjoy",  
			"BurnDrvQuizdais",  
			"BurnDrvQuizdaisk",  
			"BurnDrvLresort",  
			"BurnDrvEightman",  
			"BurnDrvLegendos",  
			"BurnDrvbb2020",  
			"BurnDrvbba2020",  
			"BurnDrvbbh2020",  
			"BurnDrvSocbrawl",  
			"BurnDrvSocbrawlh",  
			"BurnDrvFatFury1",  
			"BurnDrvRoboarmy",  
			"BurnDrvFbfrenzy",  
			"BurnDrvKotm2",  
			"BurnDrvKotm2p",  
			"BurnDrvSengoku2",  
			"BurnDrvBstars2",  
			"BurnDrvQuizdai2",  
			"BurnDrv3Countb",  
			"BurnDrvAof",  
			"BurnDrvSamSho",  
			"BurnDrvSamShoh",  
			"BurnDrvtophntr",  
			"BurnDrvtophntrh",  
			"BurnDrvFatfury2",  
			"BurnDrvSsideki",  
			"BurnDrvKof94",  
			"BurnDrvAof2",  
			"BurnDrvAof2a",  
			"BurnDrvFatfursp",  
			"BurnDrvFatfurspa",  
			"BurnDrvSavagere",  
			"BurnDrvSsideki2",  
			"BurnDrvSamSho2",  
			"BurnDrvsamsho2k",  
			"BurnDrvFatfury3",  
			"BurnDrvSsideki3",  
			"BurnDrvKof95",  
			"BurnDrvKof95a",  
			"BurnDrvKof95h",  
			"BurnDrvSamSho3",  
			"BurnDrvSamSho3h",  
			"BurnDrvfswords",  
			"BurnDrvrbff1",  
			"BurnDrvrbff1a",  
			"BurnDrvAof3",  
			"BurnDrvAof3k",  
			"BurnDrvKof96",  
			"BurnDrvKof96h",  
			"BurnDrvSsideki4",  
			"BurnDrvKizuna",  
			"BurnDrvSamSho4",  
			"BurnDrvSamSho4k",  
			"BurnDrvrbffspec",  
			"BurnDrvrbffspeck",  
			"BurnDrvKof97",
			"BurnDrvkof973v",
			"BurnDrvKof97ts",
			"BurnDrvKof97h",  
			"BurnDrvKof97k",  
			"BurnDrvKof97pls",  
			"BurnDrvKog",  
			"BurnDrvKogplus",  
			"BurnDrvlastblad",  
			"BurnDrvlastblada",  
			"BurnDrvlastbladh",  
			"BurnDrvlastsold",  
			"BurnDrvIrrmaze",  
			"BurnDrvrbff2",  
			"BurnDrvrbff2h",  
			"BurnDrvrbff2k",  
			"BurnDrvMSlug2",  
			"BurnDrvKof98",  
			"BurnDrvKof98a",  
			"BurnDrvKof98k",  
			"BurnDrvKof98ka",  
			"BurnDrvKof98h",  
			"BurnDrvlastbld2",  
			"BurnDrvNeocup98",  
			"BurnDrvMSlugX",
			"BurnDrvMSlugXh", 
			"BurnDrvkof99",  
			"BurnDrvkof99h",  
			"BurnDrvkof99e",  
			"BurnDrvkof99k",  
			"BurnDrvkof99p",  
			"BurnDrvGarou",  
			"BurnDrvgarouh",  
			"BurnDrvGaroup",  
			"BurnDrvgaroubl",  
			"BurnDrvmslug3",  
			"BurnDrvmslug3h",  
			"BurnDrvmslug3b6",  
			"BurnDrvkof2000",  
			"BurnDrvkof2000n",  
			"BurnDrvZupapa",  
			"BurnDrvSengoku3",  
			"BurnDrvkof2001",  
			"BurnDrvkof2001h",  
			"BurnDrvcthd2003",  
			"BurnDrvct2k3sp",  
			"BurnDrvct2k3sa",  
			"BurnDrvkof2002",  
			"BurnDrvkof2002b",  
			"BurnDrvkf2k2pls",  
			"BurnDrvkf2k2pla",  
			"BurnDrvkf2k2mp",  
			"BurnDrvkf2k2mp2",
			"BurnDrvkf2k2mp3",
			"BurnDrvkf2k2mp4",
			"BurnDrvkf2k2mp5",
			"BurnDrvkof10th",  
			"BurnDrvkf10thep",  
			"BurnDrvkf2k5uni",  
			"BurnDrvkof2k4se",  
			"BurnDrvmslug5",  
			"BurnDrvmslug5h",  
			"BurnDrvms5pcb",  
			"BurnDrvms5plus",  
			"BurnDrvsvcpcb",  
			"BurnDrvsvcpcba",  
			"BurnDrvsvc",  
			"BurnDrvsvcboot",  
			"BurnDrvsvcplus",  
			"BurnDrvsvcplusa",  
			"BurnDrvsvcsplus",  
			"BurnDrvsamsho5",  
			"BurnDrvsamsho5h",  
			"BurnDrvsamsho5b",  
			"BurnDrvkf2k3pcb",  
			"BurnDrvkof2003",  
			"BurnDrvkof2003h",  
			"BurnDrvkf2k3bl",  
			"BurnDrvkf2k3pl",  
			"BurnDrvkf2k3upl",  
			"BurnDrvsamsh5sp",  
			"BurnDrvsamsh5sph",  
			"BurnDrvsamsh5spho",  
			"BurnDrvmaglord",  
			"BurnDrvmaglordh",  
			"BurnDrvncombat",  
			"BurnDrvncombath",  
			"BurnDrvbjourney",  
			"BurnDrvcrsword",  
			"BurnDrvtrally",  
			"BurnDrvncommand",  
			"BurnDrvwh1",  
			"BurnDrvwh1h",  
			"BurnDrvwh1ha",  
			"BurnDrvwh2",  
			"BurnDrvwh2j",  
			"BurnDrvaodk",  
			"BurnDrvwhp",  
			"BurnDrvmosyougi",  
			"BurnDrvovertop",  
			"BurnDrvninjamas",  
			"BurnDrvtwinspri",  
			"BurnDrvzintrckb",  
			"BurnDrvviewpoin",  
			"BurnDrvjanshin",  
			"BurnDrvpulstar",  
			"BurnDrvblazstar",  
			"BurnDrvpreisle2",  
			"BurnDrvspinmast",  
			"BurnDrvwjammers",  
			"BurnDrvkarnovr",  
			"BurnDrvstrhoop",  
			"BurnDrvghostlop",  
			"BurnDrvmagdrop2",  
			"BurnDrvmagdrop3",  
			"BurnDrvnitd",  
			"BurnDrvnitdbl",  
			"BurnDrvgururin",  
			"BurnDrvmiexchng",  
			"BurnDrvpanicbom",  
			"BurnDrvkabukikl",  
			"BurnDrvneobombe",  
			"BurnDrvminasan",  
			"BurnDrvbakatono",  
			"BurnDrvturfmast",  
			"BurnDrvmslug",  
			"BurnDrvzedblade",  
			"BurnDrvs1945p",  
			"BurnDrvquizkof",  
			"BurnDrvquizkofk",  
			"BurnDrvstakwin",  
			"BurnDrvragnagrd",  
			"BurnDrvpgoal",  
			"BurnDrvstakwin2",  
			"BurnDrvshocktro",  
			"BurnDrvshocktroa",  
			"BurnDrvshocktr2",  
			"BurnDrvlans2004",  
			"BurnDrvgalaxyfg",  
			"BurnDrvwakuwak7",  
			"BurnDrvpbobblen",  
			"BurnDrvpbobblenb",  
			"BurnDrvpbobbl2n",  
			"BurnDrvpnyaa",  
			"BurnDrvmarukodq",  
			"BurnDrvdoubledr",  
			"BurnDrvgowcaizr",  
			"BurnDrvsdodgeb",  
			"BurnDrvtws96",  
			"BurnDrvfightfev",  
			"BurnDrvfightfeva",  
			"BurnDrvpspikes2",  
			"BurnDrvsonicwi2",  
			"BurnDrvsonicwi3",  
			"BurnDrvpopbounc",  
			"BurnDrvandrodun",  
			"BurnDrvpuzzledp",  
			"BurnDrvneomrdo",  
			"BurnDrvgoalx3",  
			"BurnDrvneodrift",  
			"BurnDrvbreakers",  
			"BurnDrvpuzzldpr",  
			"BurnDrvbreakrev",  
			"BurnDrvflipshot",  
			"BurnDrvctomaday",  
			"BurnDrvganryu",  
			"BurnDrvbangbead",  
			"BurnDrvmslug4",
			"BurnDrvmslug4c",
			"BurnDrvmslug4h",  
			"BurnDrvms4plus",  
			"BurnDrvrotd",  
			"BurnDrvmatrim",  
			"BurnDrvmatrimbl",  
			"BurnDrvjockeygp",  
			"BurnDrvjockeygpa",  
			"BurnDrvvliner",  
			"BurnDrvvlinero",  
			"BurnDrvdiggerma",  
			"BurnDrvbangbedp",  
			"BurnDrvcthd2k3a",  
			"BurnDrvfr2ch",  
			"BurnDrvironclad",  
			"BurnDrvironclado",  
			"BurnDrvb2buster",  
			"BurnDrvtotcarib",  
			"BurnDrvkf2k1pla",  
			"BurnDrvkf2k1pls",  
			"BurnDrvkf2k2plb", 
			"BurnDrvkf2k2tt",
			"BurnDrvkf2k2plc",  
			"BurnDrvkf2k2ps2",  
			"BurnDrvkf2k4pls",  
			"BurnDrvkof96ae",  
			"BurnDrvkof96ae20",  
			"BurnDrvkof96cn",  
			"BurnDrvkof96ep",  
			"BurnDrvkof97cn",  
			"BurnDrvkof97pla",  
			"BurnDrvKof97oro",  
			"BurnDrvkof97xt",  
			"BurnDrvkof98ae", 
			"BurnDrvkf98ae16",  
			"BurnDrvlhcdb",  
			"BurnDrvmslug5b",  
			"BurnDrvsamsho2k2",  
			"BurnDrvzintrkcd",  
			"BurnDrv4play",  
			"BurnDrvbeast",  
			"BurnDrvcnbe",  
			"BurnDrvcolumnsn",  
			"BurnDrvltorb1",  
			"BurnDrvneo2500",  
			"BurnDrvneodemo",  
			"BurnDrvneonopon",  
			"BurnDrvneopong",  
			"BurnDrvneoponga",  
			"BurnDrvngem2k",  
			"BurnDrvngfrog",  
			"BurnDrvpoknight",  
			"BurnDrvsyscheck",  
			"BurnDrvcndi",  
			"BurnDrvdwi",  
			"BurnDrvdwia",  
			"BurnDrvducki",  
			"BurnDrvghostbi",  
			"BurnDrvrobocopi",  
			"BurnDrvspidermi",  
			"BurnDrvtmnti",  
			"BurnDrvtmntia",  
			"BurnDrvneothndr",  
			"BurnDrvngftdemo",  
			"BurnDrvneocstlv",  
			"BurnDrvneo3ddmo",  
			"BurnDrvneoww2",  
			"BurnDrvkof97y",  
			"BurnDrvkof97yk",  
			"BurnDrvkof99ae",  
			"BurnDrvkof98c",  
			"BurnDrvkof98m",  
			"BurnDrvkof99evo",    
			"BurnDrvPgm",  
			"BurnDrvOrlegend",  
			"BurnDrvOrlegend112e",  
			"BurnDrvOrlegend112c",  
			"BurnDrvOrlegend112ca",  
			"BurnDrvOrlegend111c",  
			"BurnDrvOrlegend105k",  
			"BurnDrvDrgw2",  
			"BurnDrvDrgw2c",  
			"BurnDrvDrgw2j",  
			"BurnDrvDrgw2x",  
			"BurnDrvKillbld",  
			"BurnDrvKillbld104",  
			"BurnDrvOlds",  
			"BurnDrvOlds100",  
			"BurnDrvOlds100a",  
			"BurnDrvOlds103t",  
			"BurnDrvKov",  
			"BurnDrvKov115",  
			"BurnDrvKov100",  
			"BurnDrvKovplus",  
			"BurnDrvKovplusa",  
			"BurnDrvKovsh",   
			"BurnDrvKovsh102",  
			"BurnDrvKovsh101",  
			"BurnDrvKovsh100",  
			"BurnDrvPhotoy2k",  
			"BurnDrvPhotoy2k104",  
			"BurnDrvphotoy2k102",  
			"BurnDrvPuzlstar",  
			"BurnDrvPuzzli2",  
			"BurnDrvPuzzli2s",  
			"BurnDrvMartmast",  
			"BurnDrvmartmastc",  
			"BurnDrvmartmastc102",  
			"BurnDrvKov2",  
			"BurnDrvKov2106",  
			"BurnDrvKov2103",  
			"BurnDrvKov2102",  
			"BurnDrvKov2101",  
			"BurnDrvKov2100",  
			"BurnDrvKov2p",  
			"BurnDrvKov2p204",  
			"BurnDrvKov2p202",  
			"BurnDrvDdp2",  
			"BurnDrvDdp2101",  
			"BurnDrvDdp2100",  
			"BurnDrvDdp2hk",  
			"BurnDrvDdp2101hk",  
			"BurnDrvDdp2100hk",  
			"BurnDrvDdp2k",  
			"BurnDrvDdp2101k",  
			"BurnDrvDdp2100k",  
			"BurnDrvDdp2j",  
			"BurnDrvDdp2101j",  
			"BurnDrvDdp2100j",  
			"BurnDrvDdp2t",  
			"BurnDrvDdp2101t",  
			"BurnDrvDdp2100t",  
			"BurnDrvDdp2c",  
			"BurnDrvDdp2101c",  
			"BurnDrvDdp2100c",  
			"BurnDrvDw2001",  
			"BurnDrvdwpc",  
			"BurnDrvDmnfrnt",  
			"BurnDrvdmnfrntb",  
			"BurnDrvdmnfrnta",  
			"BurnDrvTheglad",  
			"BurnDrvTheglad101",  
			"BurnDrvtheglada",  
			"BurnDrvhappy6",  
			"BurnDrvhappy6101",  
			"BurnDrvkovshp",  
			"BurnDrvkovshpa",  
			"BurnDrvkovytzy",  
			"BurnDrvoldsplus",  
			"BurnDrvKillbldp",  
			"BurnDrvSvg",  
			"BurnDrvDdp3",  
			"BurnDrvDdp3a",  
			"BurnDrvDdp3b",  
			"BurnDrvDdp3blk",  
			"BurnDrvDdp3blka",  
			"BurnDrvKet",  
			"BurnDrvKetalt",  
			"BurnDrvKeta",  
			"BurnDrvKetb",  
			"BurnDrvketarr",  
			"BurnDrvketarr15",  
			"BurnDrvketarr151",  
			"BurnDrvketstoicu",  
			"BurnDrvEspgal",  
			"BurnDrvThegladpcb",  
			"BurnDrvDmnfrntpcb",  
			"BurnDrvSvgpcb",  
			"BurnDrvkovqhsgs",  
			"BurnDrvkovqhsgsa",  
			"BurnDrvkovshxas",  
			"BurnDrvKovsgqyz",  
			"BurnDrvKovsgqyza",  
			"BurnDrvKovsgqyzb",  
			"BurnDrvKovsgqyzc",  
			"BurnDrvKovshb",  
			"BurnDrvkovshpd",  
			"BurnDrvkovshpd2",  
			"BurnDrvkovshdf",  
			"BurnDrvkovshyh",  
			"BurnDrvkovshxs",  
			"BurnDrvkovshzs",  
			"BurnDrvkovplusqxlw",  
			"BurnDrvkovpluszlfy",  
			"BurnDrvkovplusqyz",  
			"BurnDrvkovp2k7",
			"BurnDrvkovp2k12",
			"BurnDrvkovp2k9",
			"BurnDrvkov2p205",
			"BurnDrvkovqm",
			"BurnDrvkovqy",
			"BurnDrvkovds",
			"BurnDrvkov2k2em",
			"BurnDrvkov2k2ws",
			"BurnDrvoldsp",
			"BurnDrvkovshh",
			"BurnDrvkovpluslssx",  
			"BurnDrvkovplusblcx",  
			"BurnDrvorlegndcbbws",  
			"BurnDrvorlegndccngl",  
			"BurnDrvorlegndcssfh",  
			"BurnDrvorlegndcqylw",  
			"BurnDrvorlegndcjhcs",  
			"BurnDrvolds100afybh",  
			"BurnDrvolds100awxnz",  
			"BurnDrvolds100awxl",  
			"BurnDrvolds100akof",  
			"BurnDrvolds100ajb",  
			"BurnDrvkovshwsgl",  
			"BurnDrvkovshkof",  
			"BurnDrvkovshlbt",  
			"BurnDrvkovshwjdz",  
			"BurnDrvkovshsjcs",  
			"BurnDrvkov2plsqx",  
			"BurnDrvkov2pplus",  
			"BurnDrvkov2psblq",  
			"BurnDrvkov2pqjn",  
			"BurnDrvkov2pmmqf",  
			"BurnDrvkovlsqh2",  
			"BurnDrvkovlsqh3"
	};
	
	public static boolean isPgmGame(String romName)
	{
		Log.i("APPCONFIG", romName);
		if(null == romName || romName.equals(""))
			return false;
		for (int i = 0; i < strPgmGame.length; i++) {
			String array_element = strPgmGame[i];
			if(array_element != null && array_element.toLowerCase().contains(romName.toLowerCase()))
				return true;
		}
		return false;
	}

	public static String filePathToURL(String path)
	{

		return "file://" + path;
	}

	static boolean isGameFile(String name)
	{
		if (name.endsWith(".fba") || name.endsWith(".zip") || name.endsWith(".iso"))
		{
			if (name.endsWith("pgm.zip") || name.endsWith("neogeo.zip"))
			{
				return false;
			}
			return true;
		}
		else
		{
			return false;
		}
	}

	public static String getNameNoExt(String path)
	{
		int start = path.lastIndexOf('/');
		int end = path.lastIndexOf('.');
		if (end == -1)
			end = path.length();
		if (start == -1)
			return path.substring(0, end);
		else if (end < start)
		{
			return path.substring(start + 1, path.length());
		}
		else
			return path.substring(start + 1, end);
	}

	public static String getNameWithExt(String path)
	{
		int start = path.lastIndexOf('/');

		return path.substring(start + 1, path.length());
	}

	public static String getRomPath(String path)
	{
		int end = path.lastIndexOf('/');

		return path.substring(0, end);
	}

	public static String getNameNoExtWithPath(String path)
	{
		int end = path.lastIndexOf('.');
		if (end == -1)
			end = path.length();
		return path.substring(0, end);
	}

	static boolean createFolder(String strFolder)
	{
		File file = new File(strFolder);
		if (!file.exists())
		{
			if (file.mkdirs()) // modify by caixi make subdirs
			{
				AppConfig.logD("mkdir: ok" + strFolder);
				return true;
			}
			else
			{
				AppConfig.logD("mkdir: failed" + strFolder);
				return false;
			}
		}
		return true;
	}

	public static String getLibpath(Context context)
	{
		String str = context.getCacheDir().getAbsolutePath();
		str = str.replace("cache", "lib");
		return str;
	}

	public static void createAppDir(Context context)
	{
		/*	File dateDir = Environment.getExternalStorageDirectory();
			PRIVATE_PATH = dateDir.getAbsolutePath() + PATH;// context.getExternalFilesDir(null).toString()+"/";
			APP_PATH = dateDir.getAbsolutePath() + PATH;// PRIVATE_PATH;//
			ROM_PATH = APP_PATH;

			// STATE_PATH = PRIVATE_PATH + ".states/";
			CONFIG_PATH = PRIVATE_PATH + CONFIG_PATH;
			INFO_PATH = PRIVATE_PATH + INFO_PATH;
			// SNAP_PATH = PRIVATE_PATH + ".snapshot/";
			// CHEAT_PATH = PRIVATE_PATH + ".cheats/";
			IPS_PATH = PRIVATE_PATH + IPS_PATH;
			TMP_PATH = PRIVATE_PATH + TMP_PATH;
			ROMDATA_PATH = PRIVATE_PATH + ROMDATA_PATH;
		 */
		createFolder(APP_PATH);
		// createFolder(STATE_PATH);
		createFolder(ROM_PATH);
		createFolder(CONFIG_PATH);
		createFolder(INFO_PATH);
		createFolder(INFO_PATH + "icon/");
		// createFolder(SNAP_PATH);
		// createFolder(CHEAT_PATH);
		createFolder(IPS_PATH);
		createFolder(TMP_PATH);
		createFolder(ROMDATA_PATH);
		createFolder(LOG_PATH);
	}

	public static void logD(String msg)
	{
		if (AppConfig.DEBUG)
			Log.d(TAG, msg);
	}

	public static void logD(String tag, String msg)
	{
		if (AppConfig.DEBUG)
			Log.d(tag, msg);
	}

	public static void logE(String msg)
	{
		//if (AppConfig.DEBUG)
		Log.e(TAG, msg);
	}





	static String getLastDir(Context context)
	{
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		return sp.getString(AppConfig.KEY_LAST_DIR, AppConfig.ROM_PATH.substring(0, AppConfig.ROM_PATH.length() - 1));
	}

	public static void saveLastDir(Context context, String path)
	{
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		Editor edit = sp.edit();
		edit.putString(AppConfig.KEY_LAST_DIR, path);
		edit.commit();
	}

	public static String getStringPref(Context context, String pref, String defval)
	{
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		return sp.getString(pref, defval);
	}

	public static void saveStringPref(Context context, String pref, String val)
	{
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		Editor edit = sp.edit();
		edit.putString(pref, val);
		edit.commit();
	}

	static boolean isFirstRun(Context context)
	{
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		boolean firstRun = sp.getBoolean(PREF_FIRST_RUN, true);
		String packageName = context.getPackageName();
		int version;
		try
		{
			version = context.getPackageManager().getPackageInfo(packageName, 0).versionCode;
			int lastVersion = sp.getInt("version", 0);
			if (lastVersion < version)
			{
				Editor edit = sp.edit();
				edit.putInt("version", version);
				edit.commit();
				firstRun = true;
			}
		} catch (NameNotFoundException e)
		{
			e.printStackTrace();
		}
		return firstRun;
	}

	static void setFirstRun(Context context, boolean first)
	{
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		Editor edit = sp.edit();
		edit.putBoolean(PREF_FIRST_RUN, first);
		edit.commit();
	}

	static boolean setDefaultConfig(Context context)
	{
		// combikey define
		setVpadStyle(context, PREF_VPAD_SKIN_1);

		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		Editor edit = sp.edit();
		AppConfig.enableAudio = true;
		AppConfig.renderMode = AppConfig.RENDER_MODE_GPU;
		AppConfig.renderQuality = true;
		AppConfig.frameSkip = -1;
		AppConfig.screenOrientation = AppConfig.ORIENT_LANDSCAPE;// AppConfig.ORIENT_LANDSCAPE;
		AppConfig.screenMode = SCREEN_MODE_FIT;
		AppConfig.enablePad = true;// show or hide virtual controller
		AppConfig.enableVibrator = false;// true;
		AppConfig.enablePhysicalKey = true;
		AppConfig.cpuCores = 2;

		edit.putBoolean(PREF_ENABLE_AUDIO, AppConfig.enableAudio);
		if (AppConfig.renderMode == AppConfig.RENDER_MODE_GPU)
		{
			edit.putBoolean(PREF_RENDER_MODE, true);
		}
		else
		{
			edit.putBoolean(PREF_RENDER_MODE, false);
		}
		edit.putBoolean(PREF_RENDER_QUALITY, AppConfig.renderQuality);
		edit.putString(PREF_SCREENT_ORIENT, String.valueOf(AppConfig.screenOrientation));
		edit.putString(PREF_FRAME_SKIP, String.valueOf(AppConfig.frameSkip));
		edit.putString(PREF_SCREEN_MODE, String.valueOf(AppConfig.screenMode));
		edit.putBoolean(PREF_ENABLE_VPAD, AppConfig.enablePad);
		edit.putBoolean(PREF_ENABLE_VIBRATOR, AppConfig.enableVibrator);
		edit.putBoolean(PREF_ENABLE_PHYSICAL_KEY, AppConfig.enablePhysicalKey);
		edit.putBoolean(PREF_HIDE_ADS, false);
		edit.putBoolean(PREF_VPAD_PLAYER, true);
		edit.putBoolean(PREF_AUTO_THREADING, true);
		edit.putBoolean(PREF_ANALOG_PRETTY, false);
		edit.putBoolean(PREF_ENABLE_ONE_CONTROLLER, false);
		edit.putString(PREF_ANALOG_DZ, "1");
		edit.putString(PREF_ANALOG_EZ, "2");
		edit.putString(PREF_BUTTON_EZ, "2");

		edit.commit();
		/*
		saveInputDevice(context, null, 0);
		saveInputDevice(context, null, 1);
		saveInputDevice(context, null, 2);
		saveInputDevice(context, null, 3);
		 */
		return true;
	}
	static void createResFile(Context context, String dirName, String[] fileNames, boolean force)
	{

		File dir = new File(dirName);
		if (!dir.exists())
		{
			dir.mkdirs();
		}
		
		File dirbios = new File(dirName + "bios");
		if (!dirbios.exists())
		{
			dirbios.mkdir();
		}
		AppConfig.logE("dirName =" +dirName);
		AssetManager asset = context.getAssets();

		for (int i = 0; i < fileNames.length; i++)
		{
			try
			{
				if (!force)
				{
					File file = new File(dirName + fileNames[i]);
					AppConfig.logE("file name =" +dirName + fileNames[i]);
					if (file.exists()) {
						long fileSize = file.length();
						InputStream in = asset.open(fileNames[i]);
						int assetSize = in.available();
						in.close();
						if(fileSize == assetSize) {
							continue;
						}
					}
					
					dir = file.getParentFile();
				}
				
				if (!dir.exists())
				{
					dir.mkdirs();
				}

				InputStream istream = asset.open(fileNames[i], AssetManager.ACCESS_BUFFER);

				OutputStream ostream = new FileOutputStream(dirName + fileNames[i]);
				byte[] buf = new byte[1024];
				int len;
			
				while ((len = istream.read(buf)) > 0)
				{
					ostream.write(buf, 0, len);
				}
				ostream.flush();
				ostream.close();
				istream.close();
				// asset.close();
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
			
				AppConfig.logE("cant install bios file");
				e.printStackTrace();
			}
		}
	}

	private static final char HEX_DIGITS[] =
		{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
		};

	public static String toHexString(byte[] b)
	{
		StringBuilder sb = new StringBuilder(b.length * 2);
		for (int i = 0; i < b.length; i++)
		{
			sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
			sb.append(HEX_DIGITS[b[i] & 0x0f]);
		}
		return sb.toString();
	}

	public static String md5sum(String filename)
	{
		File file = new File(filename);
		if (!file.exists())
			return null;

		InputStream fis;
		byte[] buffer = new byte[1024];
		int numRead = 0;
		MessageDigest md5;
		try
		{
			fis = new FileInputStream(filename);
			md5 = MessageDigest.getInstance("MD5");
			while ((numRead = fis.read(buffer)) > 0)
			{
				md5.update(buffer, 0, numRead);
			}
			fis.close();
			return toHexString(md5.digest());
		} catch (Exception e)
		{
			return null;
		}
	}

	public static String md5string(String string)
	{
		char[] carray = string.toCharArray();
		byte[] buffer = new byte[carray.length];
		for (int i = 0; i < carray.length; i++)
			buffer[i] = (byte) carray[i];
		MessageDigest md5;
		try
		{
			md5 = MessageDigest.getInstance("MD5");
			md5.update(buffer, 0, carray.length);
			return toHexString(md5.digest());
		} catch (Exception e)
		{
			return null;
		}
	}

	public static void initialise(final Context context)
	{
		boolean firstrun = isFirstRun(context);
		// String sign = FbaEmu.signData(context);
		// String md6 = md5string(sign);
		try
		{
			versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
		} catch (NameNotFoundException e)
		{
			e.printStackTrace();
		}
		createAppDir(context);
		if (firstrun)
			setDefaultConfig(context);
		updateConfig(context);

		final String[] infos =
			{ "listcn.txt", "drvrom.xml"
			};

		// final String[] cheatFile = { "cheat.zip" };
		final String[] bios =
			{ "bios/neogeo.zip", "bios/pgm.zip", "neogeo.zip", "pgm.zip"
			};
		createResFile(context, AppConfig.APP_PATH, bios, firstrun);
		copyGuide(context);
		//createResFile(context, AppConfig.CONFIG_PATH, CONFIGS, false);
		if (!firstrun)
			return;

		// String md5 = md5sum(AppConfig.CHEAT_PATH + "cheat.zip");
		// if (!"CD4A07160C717B699BC04BBC898820C5".equals(md5))
		// createResFile(context, AppConfig.CHEAT_PATH, cheatFile, true);
		createResFile(context, AppConfig.INFO_PATH, infos, true);

		// File file = new File(INFO_PATH + "icon/zzyzzyxx.ico");
		// if (!file.exists())
		// FileUtil.Unzip(context.getResources(), "gameicon.zip", INFO_PATH
		// + "icon/");

		AppConfig.setFirstRun(context, false);
	}

	public static void updateConfig(Context context)
	{
		if (context.getResources().getConfiguration().locale.getLanguage().equalsIgnoreCase("zh") || context.getResources().getConfiguration().locale.getCountry().equals("CN"))
			AppConfig.language = 1;
		else
			AppConfig.language = 0;

		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		AppConfig.enableAudio = sp.getBoolean(PREF_ENABLE_AUDIO, true);

		AppConfig.IsXperiaPlay = AppConfig.IsXperiaPlay();
		if (getNumCores() > 1 && sp.getBoolean(PREF_AUTO_THREADING, true))
			AppConfig.cpuCores = getNumCores();
		else
			AppConfig.cpuCores = 1;

		boolean renderMode = sp.getBoolean(PREF_RENDER_MODE, true);
		if (renderMode)
		{
			AppConfig.renderMode = AppConfig.RENDER_MODE_GPU;
		}
		else
		{
			AppConfig.renderMode = AppConfig.RENDER_MODE_CPU;
		}

		AppConfig.renderQuality = sp.getBoolean(PREF_RENDER_QUALITY, true);

		// String orient = sp.getString(PREF_SCREENT_ORIENT, "0");
		// if (orient.equalsIgnoreCase("0"))
		// AppConfig.screenOrientation = AppConfig.ORIENT_AUTO;
		// else if (orient.equalsIgnoreCase("1"))
		// AppConfig.screenOrientation = AppConfig.ORIENT_LANDSCAPE;
		// else if (orient.equalsIgnoreCase("2"))
		// AppConfig.screenOrientation = AppConfig.ORIENT_PORTRAIT;
		// else if (orient.equalsIgnoreCase("3"))
		// AppConfig.screenOrientation = AppConfig.ORIENT_LANDSCAPE_REV;
		// else if (orient.equalsIgnoreCase("4"))
		// AppConfig.screenOrientation = AppConfig.ORIENT_PORTRAIT_REV;

		String screen = sp.getString(PREF_SCREEN_MODE, "0");
		AppConfig.screenMode = Integer.parseInt(screen);
		// if (screen.equalsIgnoreCase("0"))
		// AppConfig.screenMode = SCREEN_MODE_FIT;
		// else if (screen.equalsIgnoreCase("1"))
		// AppConfig.screenMode = SCREEN_MODE_FULL;
		// else if (screen.equalsIgnoreCase("2"))
		// AppConfig.screenMode = SCREEN_MODE_RATIO4TO3;
		// else if (screen.equalsIgnoreCase("3"))
		// AppConfig.screenMode = SCREEN_MODE_RATIO3TO4;
		// else if (screen.equalsIgnoreCase("4"))
		// AppConfig.screenMode = SCREEN_MODE_ORIGIN;
		screen = sp.getString(PREF_FRAME_SKIP, "-1");
		AppConfig.frameSkip = Integer.parseInt(screen);

		AppConfig.turboSpeed = sp.getInt(PREF_TURBO_SPEED, 8);

		AppConfig.enableVibrator = sp.getBoolean(PREF_ENABLE_VIBRATOR, true);

		AppConfig.enablePad = sp.getBoolean(PREF_ENABLE_VPAD, true);
		AppConfig.bAutoLayoutBtn = sp.getBoolean(PREF_VPAD_AUTOLAYOUT, true);
		AppConfig.enablePhysicalKey = sp.getBoolean(PREF_ENABLE_PHYSICAL_KEY, true);
		AppConfig.oneController = sp.getBoolean(PREF_ENABLE_ONE_CONTROLLER, true);

		AppConfig.logD(AppConfig.autoSearchRom + " " + AppConfig.enableAudio + " " + AppConfig.enableVibrator + " " + AppConfig.renderMode + " " + AppConfig.screenMode + " " + AppConfig.vkeypadLayout
				+ " " + AppConfig.controlScale + " " + AppConfig.enablePhysicalKey);
	}

	public static void lockScreenOrientation(Context context, int orient)
	{
		// if (context.getResources().getConfiguration().orientation ==
		// Configuration.ORIENTATION_PORTRAIT)
		Activity act = (Activity) context;
		switch (orient)
		{
		case AppConfig.ORIENT_LANDSCAPE:
			act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
			break;
		case AppConfig.ORIENT_PORTRAIT:
			act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
			break;
		case AppConfig.ORIENT_LANDSCAPE_REV:
			act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
			break;
		case AppConfig.ORIENT_PORTRAIT_REV:
			act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
			break;
		}
	}

	/**
	 * Gets the number of cores available in this device, across all processors.
	 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
	 * 
	 * @return The number of cores, or 1 if failed to get result
	 */
	static int getNumCores()
	{
		// Private Class to display only CPU devices in the directory listing
		class CpuFilter implements FileFilter
		{
			@Override
			public boolean accept(File pathname)
			{
				// Check if filename is "cpu", followed by a single digit number
				if (Pattern.matches("cpu[0-9]", pathname.getName()))
				{
					return true;
				}
				return false;
			}
		}

		try
		{
			// Get directory containing CPU info
			File dir = new File("/sys/devices/system/cpu/");
			// Filter to only list the devices we care about
			File[] files = dir.listFiles(new CpuFilter());
			// Return the number of cores (virtual CPU devices)
			return files.length;
		} catch (Exception e)
		{
			// Default to return 1 core
			return 1;
		}
	}

	static public int getscrOrientation(Activity mm)
	{
		Display getOrient = mm.getWindowManager().getDefaultDisplay();
		// int orientation = getOrient.getOrientation();

		int orientation = mm.getResources().getConfiguration().orientation;

		// Sometimes you may get undefined orientation Value is 0
		// simple logic solves the problem compare the screen
		// X,Y Co-ordinates and determine the Orientation in such cases
		if (orientation == Configuration.ORIENTATION_UNDEFINED)
		{

			Configuration config = mm.getResources().getConfiguration();
			orientation = config.orientation;

			if (orientation == Configuration.ORIENTATION_UNDEFINED)
			{
				// if emu_height and widht of screen are equal then
				// it is square orientation
				if (getOrient.getWidth() == getOrient.getHeight())
				{
					orientation = Configuration.ORIENTATION_SQUARE;
				}
				else
				{ // if widht is less than emu_height than it is portrait
					if (getOrient.getWidth() < getOrient.getHeight())
					{
						orientation = Configuration.ORIENTATION_PORTRAIT;
					}
					else
					{ // if it is not any of the above it will defineitly
						// be landscape
						orientation = Configuration.ORIENTATION_LANDSCAPE;
					}
				}
			}
		}
		return orientation; // return values 1 is portrait and 2 is Landscape
		// Mode
	}

	static public int getVpadStyle(Context context)
	{
		return PreferenceManager.getDefaultSharedPreferences(context).getInt(PREF_VPAD_STYLE, PREF_VPAD_SKIN_1);
	}

	static public void setVpadStyle(Context context, int style)
	{
		Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
		editor.putInt(PREF_VPAD_STYLE, style);
		editor.commit();
	}

	static public boolean isTiltSensor(Context context)
	{
		return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_TILT_SENSOR, false);
	}

	static public int getTiltSensitivity(Context context)
	{
		return PreferenceManager.getDefaultSharedPreferences(context).getInt(PREF_TILT_SENSITIVITY, 6);
	}

	static public int getTiltDZ(Context context)
	{
		return Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(context).getString(PREF_TILT_DZ, "1")).intValue();
	}

	static public boolean isAnalogPretty(Context context)
	{
		/*
		 * return PreferenceManager.getDefaultSharedPreferences(context)
		 * .getBoolean(PREF_ANALOG_PRETTY, false)
		 */

		return true;
	}

	static public int getAnalogDZ(Context context)
	{
		return Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(context).getString(PREF_ANALOG_DZ, "1")).intValue();
	}

	static public int getAnalogEZ(Context context)
	{
		return Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(context).getString(PREF_ANALOG_EZ, "1")).intValue();
	}

	static public int getButtonEZ(Context context)
	{
		return Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(context).getString(PREF_BUTTON_EZ, "1")).intValue();
	}

	static public boolean hideAds(Context context)
	{
		return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_HIDE_ADS, false);
	}

	static public boolean showPlayerButton(Context context)
	{
		return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_VPAD_PLAYER, true);
	}

	public static String[] deviceName = new String[]
			{ "?", "?", "?", "?"
			};
	public static String[] deviceDescrip = new String[]
			{ "?", "?", "?", "?"
			};
	public static int[] deviceID = new int[]
			{ 0, 0, 0, 0
			};

	/*
	@TargetApi(Build.VERSION_CODES.BASE)
	public static void saveInputDevice(Context context, InputDevice device, int player_num)
	{

		if (player_num >= 0 && player_num < MAX_PLAYER)
		{
			SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
			Editor edit = sp.edit();

			if (device == null)
			{
				deviceName[player_num] = "?";
				deviceID[player_num] = 0;
				deviceDescrip[player_num] = "?";
			}
			else
			{
				deviceName[player_num] = device.getName();
				deviceID[player_num] = device.getId();

				if (Build.VERSION.SDK_INT >= 16)
				{
					deviceDescrip[player_num] = device.getDescriptor(); 
				}

				edit.putString(PREF_DEVICE_NAME + player_num, deviceName[player_num]);
				edit.putString(PREF_DEVICE_DESCRIP + player_num, deviceDescrip[player_num]);
				edit.commit();
			}
		}
	}
	 */

	public static int inputDeviceToPlayer(InputDevice device)
	{
		if (device == null)
			return -1;

		int index = 0;
		int match = 0;
		if (Build.VERSION.SDK_INT >= 16)
		{
			for (index = 0; index < MAX_PLAYER; index++)
			{
				/*
				 * if (deviceDescrip[index].equals(device.getDescriptor())) {
				 * match++; }
				 */
			}
		}
		if (match == 1)
			return index;

		for (index = 0; index < MAX_PLAYER; index++)
		{
			if (deviceName[index].equals(device.getName()))
			{
				if (deviceID[index] != 0)
				{
					if (deviceID[index] == device.getId())
					{
						return index;
					}
				}
				else if (deviceID[index] == 0)
				{
					deviceID[index] = device.getId();
					return index;
				}
			}
		}
		return 0;
	}

	public static boolean IsXperiaPlay()
	{
		return Build.MODEL.equals("R800a") || Build.MODEL.equals("R800i") || Build.MODEL.equals("R800x") || Build.MODEL.equals("R800at")
				|| Build.MODEL.equals("SO-01D") || Build.MODEL.equals("zeus");
	}

}
